# -*- coding: utf-8 -*-
# !/usr/bin/env python
import datetime
#权限密钥生成

#加密算法 encrypt
def encrypt(key, s):
    b = bytearray(str(s).encode("gbk"))
    n = len(b) # 求出 b 的字节数
    c = bytearray(n*2)
    j = 0
    for i in range(0, n):
        b1 = b[i]
        b2 = b1 ^ key # b1 = b2^ key
        c1 = b2 % 16
        c2 = b2 // 16 # b2 = c2*16 + c1
        c1 = c1 + 64
        c2 = c2 + 64 # c1,c2都是0~15之间的数,加上65就变成了A-P 的字符的编码
        c[j] = c1
        c[j+1] = c2
        j = j+2
    return c.decode("gbk")

#密钥生成器
def keyGentor(key=15, pwd="antiy"):
    key = 15
    s1 = encrypt(key, pwd)
    return s1

year = str(datetime.datetime.now().year)
month = str(datetime.datetime.now().month)
day = str(datetime.datetime.now().day)
keyGenPWD='tsgzpermissionpwd'+year+month+day
